import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:sweet_app/bloc/application_bloc.dart';
import 'package:sweet_app/bloc/bloc_provider.dart';

class DetailsPage extends StatefulWidget {
  @override
  _DetailsPageState createState() => _DetailsPageState();
}

class _DetailsPageState extends State<DetailsPage> {
  @override
  Widget build(BuildContext context) {
    final appBloc = BlocProvider.of<ApplicationBloc>(context);
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            InkWell(
              child: Container(
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(10.0),
                    border: Border.all(color: Colors.black87, width: 4.0)),
                padding: EdgeInsets.all(8.0),
                child: Text(
                  "🤠 Learn peng",
                  style: TextStyle(fontSize: 23.0, fontWeight: FontWeight.w900),
                ),
              ),
              onTap: () => _onTap(appBloc),
            ),
          ],
        ),
      ),
    );
  }

  void _onTap(ApplicationBloc appBloc) {
    showDialog(
        context: context,
        builder: (context) {
          return AlertDialog(
            content: Text("要退出该账号？"),
            actions: <Widget>[
              FlatButton(onPressed: () => _logout(appBloc), child: Text("取消")),
              FlatButton(onPressed: () => _logout(appBloc), child: Text('确定')),
            ],
          );
        });
  }

  _logout(ApplicationBloc bloc) async {
    bloc.logout();
    Navigator.pop(context);
  }
}
